package com.yun.test03generate.common;


import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
/**
 * @Author: fxy
 * @Date: 2021/09/12/7:50
 * @Description:
 */
@Data
@Accessors(chain = true)
public class QueryConditionBase implements Serializable {

    @ApiModelProperty(value = "当前页",example = "1")
    private Integer currentPage = 1;

    @ApiModelProperty(value = "每页数量,默认为10",example = "10")
    private Integer pageSize = 10;

    @ApiModelProperty(value = "排序条件")
    private String orderBy;

    /**
     * 租户Id
     */
    @ApiModelProperty(value="租户Id")
    private String tenantId;

    /**
     * 删除标志, 0-正常，1删除  默认：0
     */
    @ApiModelProperty(value="删除标志, 0-正常，1删除")
    private Integer delFlag = 0;

    /**
     * 分页开启标志, true-开启，false-关闭，默认 :true-开启分页
     */
    @ApiModelProperty(value="分页开启标志, true-开启，false-关闭，默认-true-开启分页")
    private Boolean pageFlag = true;

    /**
     * @return the currentPage
     */
    public Integer getCurrentPage() {
        return currentPage;
    }
    /**
     * @param currentPage the currentPage to set
     */
    public QueryConditionBase setCurrentPage(Integer currentPage) {
        if (currentPage != null) {
            this.currentPage = currentPage > 1 ? currentPage : 1;
        }
        return this;
    }

    /**
     * @return the pageSize
     */
    public Integer getPageSize() {
        return pageSize != null ? pageSize : currentPageSize();
    }

/*    public void generatePageInfo() {
        if (pageFlag != null && pageFlag) {
            if (currentPage == null || currentPage <= 0){
                currentPage = 1;
            }
            if(StringUtils.isNotBlank(this.getOrderBy())){
                PageHelper.startPage(currentPage, pageSize,this.getOrderBy());
            }else {
                PageHelper.startPage(currentPage, pageSize);
            }
        } else {
            PageHelper.clearPage();
        }

    }*/

    private int currentPageSize() {
        return this.pageSize == null ? 20 : this.pageSize;
    }

}